package com.vcs.frm.web.school;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpSession;
import javax.validation.Valid;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import com.vcs.frm.web.form.school.NewAdmissionEnquiryForm;

@Controller
@RequestMapping("/school/newEnquiry")
public class NewAdmissionEnquiryController {

	

	public NewAdmissionEnquiryController() {
	}

	@RequestMapping(method = RequestMethod.GET)
	public ModelAndView showNewAdmissionForm(Model model) {
		ModelAndView mav = new ModelAndView();

		Map<String, String> sex = new HashMap<String, String>();
		sex.put("m", "Male");
		sex.put("f", "Female");
		mav.addObject("sex", sex);

		List<Integer> age = new ArrayList<Integer>();
		for (int i = 1; i <= 20; i++) {
			age.add(i);
		}

		mav.addObject("age", age);
		
		NewAdmissionEnquiryForm inquiryForm = new NewAdmissionEnquiryForm();
		mav.addObject("inquiryForm", inquiryForm);
		mav.setViewName("newEnquiry");
		return mav;
	}

	@RequestMapping(method = RequestMethod.POST)
	public ModelAndView processNewAdmissionForm(
			@ModelAttribute("inquiryForm") @Valid NewAdmissionEnquiryForm inquiryForm,
			BindingResult bindingResult, Model model, HttpSession session) {
		ModelAndView mav = new ModelAndView();

		Map<String, String> sex = new HashMap<String, String>();
		sex.put("m", "Male");
		sex.put("f", "Female");
		mav.addObject("sex", sex);

		List<Integer> age = new ArrayList<Integer>();
		for (int i = 1; i <= 20; i++) {
			age.add(i);
		}
		
		System.out.println(inquiryForm);
		mav.addObject("inquiryForm", inquiryForm);
		mav.setViewName("newEnquiry");
		return mav;
	}

}
